import { Message } from "element-ui";
import { generateId } from "@/utils";
import { formulaList } from '@/api/assets'
import _ from 'lodash'
import Vue from 'vue'
const state = {
    warningList: [
        {
            data1: "立式真空气锌炉",
            data2: "27",
            data3: "174899",
            data4: "2021-11-9 09:02",
            data5: "Alam_Tempenalure+",
            data6: "1区保温温度上限报警",
            data7: "2021-11-10 09:02",
            data8: true,
        },
        {
            data1: "卧式真空炉",
            data2: "59",
            data3: "174819",
            data4: "2021-11-10 09:02",
            data5: "Alam_Out",
            data6: "保温时间超时",
            data7: "2021-11-10 09:02",
            data8: true,
        },
        {
            data1: "卧式真空炉",
            data2: "33",
            data3: "174819",
            data4: "2021-11-10 09:02",
            data5: "Alam_Out",
            data6: "保温时间超时",
            data7: "2021-11-10 09:02",
            data8: false,
        },
        {
            data1: "箱式电炉",
            data2: "30",
            data3: "174819",
            data4: "2021-11-10 09:02",
            data5: "Alam_Tempenalure",
            data6: "1区保温温度上限报警",
            data7: "2021-11-10 09:02",
            data8: false,
        },
        {
            data1: "箱式电炉",
            data2: "59",
            data3: "122819",
            data4: "2021-11-10 09:02",
            data5: "Alam_Tempenalure",
            data6: "保温时间超时",
            data7: "2021-11-10 09:02",
            data8: false,
        },
        {
            data1: "箱式电炉",
            data2: "23",
            data3: "13452",
            data4: "2021-11-10 09:02",
            data5: "Alam_Tempenalure",
            data6: "保温时间超时",
            data7: "2021-11-10 09:02",
            data8: false,
        },
        {
            data1: "立式真空气锌炉",
            data2: "27",
            data3: "174899",
            data4: "2021-11-9 09:02",
            data5: "Alam_Tempenalure+",
            data6: "1区保温温度上限报警",
            data7: "2021-12-10 09:02",
            data8: false,
        },
        {
            data1: "卧式真空炉",
            data2: "Z8",
            data3: "425213",
            data4: "2021-11-9 09:02",
            data5: "Alam_Tempenalure+",
            data6: "保温温度上限告警",
            data7: "2021-11-20 09:02",
            data8: false,
        },
        {
            data1: "立式真空气锌炉",
            data2: "Z6",
            data3: "54199",
            data4: "2021-11-9 09:02",
            data5: "Alam_Tempenalure+",
            data6: "保温温度上限告警",
            data7: "2021-11-12 09:02",
            data8: false,
        },
        {
            data1: "箱式电炉",
            data2: "23",
            data3: "13452",
            data4: "2021-11-10 09:02",
            data5: "Alam_Tempenalure",
            data6: "保温时间超时",
            data7: "2021-11-10 09:02",
            data8: false,
        },
        {
            data1: "立式真空气锌炉",
            data2: "27",
            data3: "174899",
            data4: "2021-11-9 09:02",
            data5: "Alam_Tempenalure+",
            data6: "1区保温温度上限报警",
            data7: "2021-12-10 09:02",
            data8: false,
        },
        {
            data1: "卧式真空炉",
            data2: "Z8",
            data3: "425213",
            data4: "2021-11-9 09:02",
            data5: "Alam_Tempenalure+",
            data6: "保温温度上限告警",
            data7: "2021-11-20 09:02",
            data8: false,
        },
        {
            data1: "立式真空气锌炉",
            data2: "17",
            data3: "171899",
            data4: "2021-11-9 09:02",
            data5: "Alam_Tempenalure+",
            data6: "1区保温温度上限报警",
            data7: "2021-11-10 09:02",
            data8: false,
        },
        {
            data1: "卧式真空炉",
            data2: "Z8",
            data3: "274819",
            data4: "2021-11-10 09:02",
            data5: "Alam_Out",
            data6: "保温时间超时",
            data7: "2021-11-10 09:02",
            data8: false,
        },
        {
            data1: "箱式电炉",
            data2: "23",
            data3: "13452",
            data4: "2021-11-10 09:02",
            data5: "Alam_Tempenalure",
            data6: "保温时间超时",
            data7: "2021-11-10 09:02",
            data8: false,
        },
        {
            data1: "立式真空气锌炉",
            data2: "27",
            data3: "174899",
            data4: "2021-11-9 09:02",
            data5: "Alam_Tempenalure+",
            data6: "1区保温温度上限报警",
            data7: "2021-12-10 09:02",
            data8: false,
        },
        {
            data1: "卧式真空炉",
            data2: "Z8",
            data3: "425213",
            data4: "2021-11-9 09:02",
            data5: "Alam_Tempenalure+",
            data6: "保温温度上限告警",
            data7: "2021-11-20 09:02",
            data8: false,
        },
        {
            data1: "井式回火炉",
            data2: "Z2",
            data3: "314819",
            data4: "2021-11-10 09:02",
            data5: "Alam_Out",
            data6: "真空泵故障",
            data7: "2021-11-10 09:02",
            data8: false,
        },
        {
            data1: "箱式电炉",
            data2: "20",
            data3: "124819",
            data4: "2021-11-10 09:02",
            data5: "Alam_Tempenalure",
            data6: "1区保温温度上限报警",
            data7: "2021-11-10 09:02",
            data8: false,
        },
        {
            data1: "井式回火炉",
            data2: "51",
            data3: "122839",
            data4: "2021-11-10 09:02",
            data5: "Alam_Tempenalure",
            data6: "真空泵故障",
            data7: "2021-11-10 09:02",
            data8: false,
        },
    ],
    partsList: [{
        partName: "X20螺母",
        id: "618d61f9-ea90-4f22-9e98-70148e3390ef"
    }],//零件
    deviceRow: {},//设备信息
    deviceRowZ8: {},//设备信息
    workTableDataZ8: [
        {
            data1: '工艺结束',
            data2: '950',
            data3: '±10',
            data4: '50',
            data5: '关闭',
            data6: '0',
            data7: '真空到',
            data8: '',
            data9: '',
            data10: '',
            data11: '',
            id: generateId()
        },
        {
            data1: '工艺结束',
            data2: '950',
            data3: '±10',
            data4: '200',
            data5: '关闭',
            data6: '0',
            data7: '真空到',
            data8: '',
            data9: '',
            data10: '',
            data11: '',
            id: generateId()
        },

    ],
    workTableData: [
        {
            data8: "",//当前温度
            num: "1", //阶段
            temperature: "150",//装炉温度
            processTime: "500",//设定温度
            deadZone: "±10",//温度偏量
            controlStrategy: "100",//设定时间
            data7: '100', //最短时间
            time1: "150", //最长时间
            data1: "±2", //补偿值
            data2: "标准值策略", //控制策略
            data3: "SV", //随动策略
            data4: "", //开始时间
            data5: "", //剩余时间
            data6: "", //结束时间
            state: "",//状态
            id: generateId(),
            temperature_1: '5℃/分钟'
        },
        {
            temperature_1: '8℃/分钟',
            data8: "",//当前温度
            num: "1", //阶段
            temperature: "-",//装炉温度
            processTime: "500",//设定温度
            deadZone: "±10",//温度偏量
            controlStrategy: "200",//设定时间
            time1: "220", //最长时间
            data7: '150', //最短时间
            data1: "±2", //补偿值
            data2: "标准值策略", //控制策略
            data3: "SV", //随动策略
            data4: "", //开始时间
            data5: "", //剩余时间
            data6: "", //结束时间
            state: "",//状态
            data7: "",//当前温度
            id: generateId()
        },
        {
            temperature_1: '-',
            data8: "",//当前温度
            num: "1", //阶段
            temperature: "-",//装炉温度
            processTime: "950",//设定温度
            deadZone: "±10",//温度偏量
            controlStrategy: "150",//设定时间
            time1: "200", //最长时间
            data7: '150', //最短时间
            data1: "±2", //补偿值
            data2: "标准值策略", //控制策略
            data3: "SV", //随动策略
            data4: "", //开始时间
            data5: "", //剩余时间
            data6: "", //结束时间
            state: "",//状态
            id: generateId()
        },
        {
            temperature_1: '-',
            data8: "",//当前温度
            num: "1", //阶段
            temperature: "-",//装炉温度
            processTime: "950",//设定温度
            deadZone: "±10",//温度偏量
            controlStrategy: "300",//设定时间
            time1: "350", //最长时间
            data7: '280', //最短时间
            data1: "±2", //补偿值
            data2: "下限值策略", //控制策略
            data3: "SV", //随动策略
            data4: "", //开始时间
            data5: "", //剩余时间
            data6: "", //结束时间
            state: "",//状态
            id: generateId()
        },

    ],
}
const getters = {
    // 零件信息
    getPartsDets: state => {
        return function (id) {
            return state.partsList.find(item => item.id == id)
        }
    },
}
const mutations = {
    // 工艺配方编辑
    setDivToken(state, row) {
        state.deviceRow = row
    },
    setDivTokenZ8(state, row) {
        state.deviceRowZ8 = row
    },
    // 工艺配方编辑
    editWorkTableData(state, row) {
        const index = state.workTableData.findIndex(item => item.id == row.id)
        Vue.set(state.workTableData, index, row)

    },
    editWorkTableDataZ8(state, row) {
        const index = state.workTableDataZ8.findIndex(item => item.id == row.id)
        Vue.set(state.workTableDataZ8, index, row)

    },
    addWorkTableDataZ8: (state, row) => {
        Message({
            message: '添加成功',
            type: 'success'
        })
        state.workTableDataZ8.push({
            ...row,
            id: generateId(), //从新生成一个随机id
        })
    },
    addWorkTableData: (state, row) => {
        Message({
            message: '添加成功',
            type: 'success'
        })
        state.workTableData.push({
            ...row,
            id: generateId(), //从新生成一个随机id
            data4: "", //开始时间
            data5: "", //剩余时间
            data6: "", //结束时间
            // controlStrategy: "09:16",//设定时间
            state: "",//状态
            deadZone: '±',
            data1: '±',

        })
    },
    delWorkTableData: (state, index) => {
        Message({
            message: '删除成功',
            type: 'success'
        })
        state.workTableData.splice(index, 1)
    },
    delWorkTableDataZ8: (state, index) => {
        Message({
            message: '删除成功',
            type: 'success'
        })
        state.workTableDataZ8.splice(index, 1)
    },
    //添加零件
    addParts(state, data) {
        state.partsList = _.cloneDeep(data)
        Message({
            message: '导入成功',
            type: 'success'
        })
        console.log('state.partsList :>> ', state.partsList);
    }
}

const actions = {
    getFormlas({ state, commit, rootState }, data) {
        return new Promise((resolve) => {
            var that = this;
            var params = {
                page: 1,
                pageSize: 0,
                // rnb: Date.parse(new Date()),
                // deviceToken: data.deviceToken,
                // batchNumber: data.batchNumber
            };
            formulaList(params).then(res => {
                console.log(res.data.results, '批次')
                resolve(res.data.results);
            })

        });
    },
}

export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}
